<template>
  <view class="swiper-container">
    <swiper class="swiper" 
            circular 
            autoplay 
            interval="3000" 
            duration="500" 
            @change="onChange">
      <swiper-item v-for="(item, index) in swiperList" :key="index">
        <image :src="item.imageUrl" 
               mode="aspectFill" 
               class="swiper-image"
               @tap="handleClick(item)">
        </image>
      </swiper-item>
    </swiper>
    <!-- 指示点 -->
    <view class="dots">
      <view class="dot" 
            v-for="(item, index) in swiperList" 
            :key="index"
            :class="{ active: current === index }">
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      current: 0,
      swiperList: [
        {
          imageUrl: '/static/swiper/1.jpg',
          link: ''
        },
        {
          imageUrl: '/static/swiper/2.jpg',
          link: ''
        },
        {
          imageUrl: '/static/swiper/3.jpg',
          link: ''
        },
        {
          imageUrl: '/static/swiper/4.jpg',
          link: ''
        },
        {
          imageUrl: '/static/swiper/5.jpg',
          link: ''
        }
      ]
    }
  },
  methods: {
    onChange(e) {
      this.current = e.detail.current
    },
    handleClick(item) {
      if (item.link) {
        uni.navigateTo({
          url: item.link
        })
      }
    }
  }
}
</script>

<style>
.swiper-container {
  width: 100%;
  height: 400rpx;  /* 调整高度以适应图片 */
  position: relative;
}

.swiper {
  width: 100%;
  height: 100%;
}

.swiper-image {
  width: 100%;
  height: 100%;
}

.dots {
  position: absolute;
  bottom: 20rpx;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
}

.dot {
  width: 12rpx;
  height: 12rpx;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.6);
  margin: 0 8rpx;
  transition: all 0.3s;
}

.dot.active {
  width: 24rpx;
  border-radius: 6rpx;
  background-color: #fff;
}
</style>